package mes.kanban.respository;

import java.util.List;

import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import mes.kanban.entity.MesRole;

/**
 * 角色
 * @author gjy
 *
 * 2018年2月11日下午3:02:41
 */
@Repository
public interface UserRoleRespository extends BaseJpaRespository<MesRole, String>{

	@Query(nativeQuery=true,value="select r.* from mes_role r LEFT JOIN mes_user_role ur ON r.id = ur.role_id LEFT JOIN mes_user u ON u.id = ur.user_id where u.user_code = ?")
	List<MesRole> findRoleByUserCode(String userCode);

	@Query(nativeQuery=true,value="select r.* from mes_role r LEFT JOIN mes_user_role ur ON r.id = ur.role_id LEFT JOIN mes_user u ON u.id = ur.user_id where ur.user_id = ?")
	List<MesRole> getRoleByuserId(String UserId);

	@Query(nativeQuery=true,value="select r.* from mes_role r LEFT JOIN mes_user_role ur ON r.id = ur.role_id LEFT JOIN mes_user u ON u.id = ur.user_id where ur.user_id = ?")
	List<MesRole> getRoleListByUserId(String userId);

	@Query(nativeQuery=true,value="delete from mes_user_role  where user_id = ?")
	@Modifying
	void deleteRoleAndUserByUserId(String userId);

	@Query(nativeQuery=true,value="delete from mes_role_permission  where role_id = ?")
	@Modifying
	void deleteRoleAndPermissionByRoleId(String roleId);

	@Query(nativeQuery=true,value="delete from mes_role_job  where role_id = ?")
	@Modifying
	void deleteRoleAndJobByRoleId(String roleId);

	

}
